styleproperty: Make _gtk_style_property_query() take a GValue
authorBenjamin Otte <otte@redhat.com>
Mon, 26 Mar 2012 05:08:24 +0000 (07:08 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 17 Apr 2012 06:59:11 +0000 (08:59 +0200)
... and don't make it return a GtkCssValue. We want to use this for
compat with the old GValue APIs after all...

gtk/gtkcssshorthandproperty.c
gtk/gtkcssshorthandpropertyimpl.c
gtk/gtkcssshorthandpropertyprivate.h
gtk/gtkcssstyleproperty.c
gtk/gtkstylecontext.c
gtk/gtkstyleproperties.c
gtk/gtkstyleproperty.c
gtk/gtkstylepropertyprivate.h

index f9617914abf11590ea3a8705a3c998966a9c344d..6905b4568a852e81185da8980d8cacb8a6991987 100644 (file)
@@ -72,14 +72,15 @@ _gtk_css_shorthand_property_assign (GtkStyleProperty   *property,
   shorthand->assign (shorthand, props, state, value);
 }
 
-static GtkCssValue *
+static void
 _gtk_css_shorthand_property_query (GtkStyleProperty   *property,
+                                   GValue             *value,
                                    GtkStyleQueryFunc   query_func,
                                    gpointer            query_data)
 {
   GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (property);
 
-  return shorthand->query (shorthand, query_func, query_data);
+  return shorthand->query (shorthand, value, query_func, query_data);
 }
 
 static void
index 05a027c53e87d53a3fdbe495ba6967fbd901a29c..19c78951d376654ea83a81dc7f2a0f160d965ad8 100644 (file)
@@ -609,8 +609,9 @@ unpack_border (GtkCssShorthandProperty *shorthand,
   g_value_unset (&v);
 }
 
-static GtkCssValue *
+static void
 pack_border (GtkCssShorthandProperty *shorthand,
+             GValue                  *value,
              GtkStyleQueryFunc        query_func,
              gpointer                 query_data)
 {
@@ -635,7 +636,8 @@ pack_border (GtkCssShorthandProperty *shorthand,
   if (v)
     border.left = _gtk_css_value_get_int (v);
 
-  return _gtk_css_value_new_from_border (&border);
+  g_value_init (value, GTK_TYPE_BORDER);
+  g_value_set_boxed (value, &border);
 }
 
 static void
@@ -659,15 +661,16 @@ unpack_border_radius (GtkCssShorthandProperty *shorthand,
   g_value_unset (&v);
 }
 
-static GtkCssValue *
+static void
 pack_border_radius (GtkCssShorthandProperty *shorthand,
+                    GValue                  *value,
                     GtkStyleQueryFunc        query_func,
                     gpointer                 query_data)
 {
   const GtkCssBorderCornerRadius *top_left;
   GtkCssStyleProperty *prop;
   GtkCssValue *v;
-  int value = 0;
+  int i = 0;
 
   prop = GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("border-top-left-radius"));
   v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
@@ -675,10 +678,11 @@ pack_border_radius (GtkCssShorthandProperty *shorthand,
     {
       top_left = _gtk_css_value_get_border_corner_radius (v);
       if (top_left)
-        value = top_left->horizontal.value;
+        i = top_left->horizontal.value;
     }
 
-  return _gtk_css_value_new_from_int (value);
+  g_value_init (value, G_TYPE_INT);
+  g_value_set_int (value, i);
 }
 
 static void
@@ -761,8 +765,9 @@ unpack_font_description (GtkCssShorthandProperty *shorthand,
     }
 }
 
-static GtkCssValue *
+static void
 pack_font_description (GtkCssShorthandProperty *shorthand,
+                       GValue                  *value,
                        GtkStyleQueryFunc        query_func,
                        gpointer                 query_data)
 {
@@ -796,7 +801,8 @@ pack_font_description (GtkCssShorthandProperty *shorthand,
   if (v)
     pango_font_description_set_weight (description, _gtk_css_value_get_pango_weight (v));
 
-  return _gtk_css_value_new_take_font_description (description);
+  g_value_init (value, PANGO_TYPE_FONT_DESCRIPTION);
+  g_value_take_boxed (value, description);
 }
 
 static void
@@ -817,30 +823,24 @@ unpack_to_everything (GtkCssShorthandProperty *shorthand,
     }
 }
 
-static GtkCssValue *
+static void
 pack_first_element (GtkCssShorthandProperty *shorthand,
+                    GValue                  *value,
                     GtkStyleQueryFunc        query_func,
                     gpointer                 query_data)
 {
   GtkCssStyleProperty *prop;
-  GtkCssValue *v;
-  guint i;
 
   /* NB: This is a fallback for properties that originally were
    * not used as shorthand. We just pick the first subproperty
    * as a representative.
    * Lesson learned: Don't query the shorthand, query the 
    * real properties instead. */
-  for (i = 0; i < _gtk_css_shorthand_property_get_n_subproperties (shorthand); i++)
-    {
-      prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 0);
-      v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
-      if (v)
-        {
-          return _gtk_css_value_ref (v);
-        }
-    }
-  return NULL;
+  prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 0);
+  _gtk_style_property_query (GTK_STYLE_PROPERTY (prop),
+                             value,
+                             query_func,
+                             query_data);
 }
 
 static void
index 9a79a3d6c8413e4569b48ad983c6252da8d32143..4592949a56ab12dac48ae5795c32ab2790f09a38 100644 (file)
@@ -46,7 +46,8 @@ typedef void                  (* GtkCssShorthandPropertyAssignFunc)     (GtkCssS
                                                                          GtkStyleProperties      *props,
                                                                          GtkStateFlags            state,
                                                                          const GValue            *value);
-typedef GtkCssValue *         (* GtkCssShorthandPropertyQueryFunc)      (GtkCssShorthandProperty *shorthand,
+typedef void                  (* GtkCssShorthandPropertyQueryFunc)      (GtkCssShorthandProperty *shorthand,
+                                                                         GValue                  *value,
                                                                          GtkStyleQueryFunc        query_func,
                                                                          gpointer                 query_data);
 
index e783aa02c2715f5d657e19c2e1d8f83819b4fd3a..4e14cd4a0992ae9306f7c64d4b76b3b9b56d0398 100644 (file)
@@ -132,8 +132,9 @@ _gtk_css_style_property_assign (GtkStyleProperty   *property,
   _gtk_css_value_unref (css_value);
 }
 
-static GtkCssValue *
+static void
 _gtk_css_style_property_query (GtkStyleProperty   *property,
+                               GValue             *value,
                                GtkStyleQueryFunc   query_func,
                                gpointer            query_data)
 {
@@ -150,11 +151,11 @@ _gtk_css_style_property_query (GtkStyleProperty   *property,
           cairo_surface_t *surface;
           cairo_matrix_t matrix;
           
-          if (image == NULL)
-           return _gtk_css_value_new_from_pattern (NULL);
-          else if (GTK_IS_CSS_IMAGE_GRADIENT (image))
-           return _gtk_css_value_new_from_pattern (GTK_CSS_IMAGE_GRADIENT (image)->pattern);
-          else
+          g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN);
+
+          if (GTK_IS_CSS_IMAGE_GRADIENT (image))
+           g_value_set_boxed (value, GTK_CSS_IMAGE_GRADIENT (image)->pattern);
+          else if (image != NULL)
             {
               double width, height;
 
@@ -165,19 +166,24 @@ _gtk_css_style_property_query (GtkStyleProperty   *property,
               cairo_matrix_init_scale (&matrix, width, height);
               cairo_pattern_set_matrix (pattern, &matrix);
               cairo_surface_destroy (surface);
-             return _gtk_css_value_new_take_pattern (pattern);
+             g_value_take_boxed (value, pattern);
             }
         }
       else if (_gtk_css_value_holds (css_value, GTK_TYPE_CSS_NUMBER))
         {
-         int v = round (_gtk_css_number_get (_gtk_css_value_get_number (css_value), 100));
-         return _gtk_css_value_new_from_int (v);
+          g_value_init (value, G_TYPE_INT);
+         g_value_set_int (value, round (_gtk_css_number_get (_gtk_css_value_get_number (css_value), 100)));
         }
       else
-       return _gtk_css_value_ref (css_value);
+        {
+          _gtk_css_value_init_gvalue (css_value, value);
+        }
     }
   else
-    return _gtk_css_value_ref (_gtk_css_style_property_get_initial_value (GTK_CSS_STYLE_PROPERTY (property)));
+    {
+      _gtk_css_value_init_gvalue (_gtk_css_style_property_get_initial_value (GTK_CSS_STYLE_PROPERTY (property)),
+                                  value);
+    }
 }
 
 static gboolean
index 2072d4225d4dfebecdf21c93abe308974b5a2f4b..d74232c61188b9c1f5c9040adc5e96f3d5a7f13d 100644 (file)
@@ -1345,7 +1345,6 @@ gtk_style_context_get_property (GtkStyleContext *context,
   GtkStyleContextPrivate *priv;
   GtkStyleProperty *prop;
   StyleData *data;
-  GtkCssValue *v;
 
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
   g_return_if_fail (property != NULL);
@@ -1367,9 +1366,7 @@ gtk_style_context_get_property (GtkStyleContext *context,
     }
 
   data = style_data_lookup (context, state);
-  v = _gtk_style_property_query (prop, gtk_style_context_query_func, data->store);
-  _gtk_css_value_init_gvalue (v, value);
-  _gtk_css_value_unref (v);
+  _gtk_style_property_query (prop, value, gtk_style_context_query_func, data->store);
 }
 
 /**
index d63b659dde80d5c25ca97b8176c072d8893950f0..5446d9975c219a5e8b021bd40864eadb6293bea7 100644 (file)
@@ -638,7 +638,6 @@ gtk_style_properties_get_property (GtkStyleProperties *props,
 {
   StyleQueryData query = { props, state };
   GtkStyleProperty *node;
-  GtkCssValue *v;
 
   g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), FALSE);
   g_return_val_if_fail (property != NULL, FALSE);
@@ -656,11 +655,10 @@ gtk_style_properties_get_property (GtkStyleProperties *props,
       return FALSE;
     }
 
-  v = _gtk_style_property_query (node,
-                                style_query_func,
-                                &query);
-  _gtk_css_value_init_gvalue (v, value);
-  _gtk_css_value_unref (v);
+  _gtk_style_property_query (node,
+                             value,
+                             style_query_func,
+                             &query);
 
   return TRUE;
 }
index c70c76fdd49268103ecec0748715743943f22b4f..7418b93c1a1c1cf98e9665520650058aedc6689a 100644 (file)
@@ -205,19 +205,21 @@ _gtk_style_property_assign (GtkStyleProperty   *property,
  * turn gtk_style_context_get() and similar functions to get the
  * value to return to code using old APIs.
  **/
-GtkCssValue *
+void
 _gtk_style_property_query (GtkStyleProperty  *property,
+                           GValue            *value,
                            GtkStyleQueryFunc  query_func,
                            gpointer           query_data)
 {
   GtkStylePropertyClass *klass;
 
-  g_return_val_if_fail (GTK_IS_STYLE_PROPERTY (property), NULL);
-  g_return_val_if_fail (query_func != NULL, NULL);
+  g_return_if_fail (value != NULL);
+  g_return_if_fail (GTK_IS_STYLE_PROPERTY (property));
+  g_return_if_fail (query_func != NULL);
 
   klass = GTK_STYLE_PROPERTY_GET_CLASS (property);
 
-  return klass->query (property, query_func, query_data);
+  return klass->query (property, value, query_func, query_data);
 }
 
 void
index 898b97f776dc29e3922ea1a139b3d93d1300e443..d1691391a3c59bbe4394205117302c18972338fc 100644 (file)
@@ -57,7 +57,8 @@ struct _GtkStylePropertyClass
                                                             GtkStyleProperties     *props,
                                                             GtkStateFlags           state,
                                                             const GValue           *value);
-  GtkCssValue *     (* query)                              (GtkStyleProperty       *property,
+  void              (* query)                              (GtkStyleProperty       *property,
+                                                            GValue                 *value,
                                                             GtkStyleQueryFunc       query_func,
                                                             gpointer                query_data);
   gboolean          (* parse_value)                        (GtkStyleProperty *      property,
@@ -82,7 +83,8 @@ gboolean                 _gtk_style_property_parse_value   (GtkStyleProperty *
                                                             GFile                  *base);
 
 GType                    _gtk_style_property_get_value_type(GtkStyleProperty *      property);
-GtkCssValue *            _gtk_style_property_query         (GtkStyleProperty *      property,
+void                     _gtk_style_property_query         (GtkStyleProperty *      property,
+                                                            GValue                 *value,
                                                             GtkStyleQueryFunc       query_func,
                                                             gpointer                query_data);
 void                     _gtk_style_property_assign        (GtkStyleProperty       *property,